package com.sunwayworld.basemodule.rm.archivesmanage.io;

import com.sunwayworld.baseline.framework.utils.TemplateExcelHelper;
import com.sunwayworld.basemodule.basedata.exporttemplate.service.LimsGenericTemplateService;
import com.sunwayworld.framework.spring.annotation.GikamBean;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.springframework.stereotype.Component;

import java.io.*;
import java.nio.file.Path;

@GikamBean
@Component(value = "LimsArchivesExportTemplate")
public class LimsArchivesExportTemplate implements LimsGenericTemplateService<String> {

    @Override
    public void initTemplateData(Path path, String id) {
        try {
            InputStream in = new FileInputStream(path.toString());
            Workbook workBook = WorkbookFactory.create(in);
            Sheet sheet = workBook.getSheetAt(0);

            // 根据选择内容填充下拉框
            String[] columns = new String[]{"archivesType"};
            String[] codeCategoryIds = new String[]{"archivesType"};
            TemplateExcelHelper.fillSheetSelect(sheet, 0, columns, codeCategoryIds);

            in.close();
            OutputStream outputStream = new FileOutputStream(path.toString());
            workBook.write(outputStream);
            outputStream.close();
            workBook.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
